<?php
/**
 * Created by PhpStorm.
 * User: gzc0918
 * Date: 2021-08-06
 * Time: 23:24
 */

namespace IMooc;


use IMooc\Database\MySQLi;

class Factory
{
    static function createDatabase()
    {
        $db = new Database();
        Register::set('db1', $db);
        return $db;
    }
    static function getDatabase()
    {
        $db = new MySQLi();
        $db->connect('127.0.0.1', 'root', 'root', 'test');
        $key = 'db_test';
        Register::set($key, $db);
        return Register::get($key);
    }
    static function getUser($id)
    {
        $key = 'user_'.$id;
        $user = Register::get($key);
        if (!$user){
            $user = new User($id);
            Register::set($key, $user);
        }
        return $user;
    }
}